jclass={
    initPage:function(){
        // 绑定dom对象
        this.obj = {
            searchText:$('#searchText'),
        };
        // 声明全局变量
        this.data = {
            datatable:[],
            tableParams: {
                platforType: '',
                platformId: '',
                platformName    : '',
                handleBeginTime: '',
                handleEndTime: '',
                page:1,
                size:10,
                commandCode: "0x9301"
            }
        };
        this.selectedValue();
        this.getTableList();
        // this.creatTable();
        this.init();
        this.bindEvent();
    },
    init() {
        let that = this
        //十分年月日范围
        $('.J-datepickerTime-range').datePicker({
            format: 'YYYY-MM-DD HH:mm',
            isRange: true,
            hide: function (type) {
                // console.info(this.$input.eq(0).val(), this.$input.eq(1).val());
                that.data.tableParams.handleBeginTime = this.$input.eq(0).val()
                that.data.tableParams.handleEndTime = this.$input.eq(1).val()
            }
        });

        // this.setTimeDefault()

        // 重置
        $("#resetClick").click(() => {
            $('.ju-select input').val("全部")
            $("select").prop("selectedIndex",0)
            $("#search_input_platfrom").val("")
            $("#search_time input").val("")

            this.data.tableParams = {
                platforType: '',
                platformId: '',
                platformName    : '',
                handleBeginTime: '',
                handleEndTime: '',
                page:1,
                size:10,
                commandCode: "0x9301"
            }
        })

        // 查询
        $("#searchClick").click(() => {
            this.data.tableParams.page = 1;
            this.data.tableParams.size = 10;
            this.getTableList()
        })

        $("select").prop("selectedIndex",0)
        $("select").find("option").each(function() {
            $(this).removeAttr("selected");
        });

        $("#objectSelect option:first").attr("selected",true)

        jrequest.get("/api/command-problem",{}).then(res => {
            // let options = ''
            // res.data.forEach(item => {
            //     options += `<option value=${item.id}>${item.informationProblem}</option>`
            // })
            // $("#cgin_select").html(options)
            res.data.forEach(item => {
                item.name = item.informationProblem
                item.val = item.id
            })
            jdSelect.JdSelectRadioInit('#dselect_cgxx',res.data,(select) => {
                
            })
        })

    },
    setTimeDefault() {
        var startTime = moment().subtract(7, 'days').format('YYYY-MM-DD HH:mm');
        var lateDay = moment().subtract(1, 'days').format('YYYY-MM-DD HH:mm');
        $(".time-start").val(startTime);
        $(".time-end").val(lateDay);
    },
    bindEvent() {
        // 查岗弹框
        $("#dialogUser").hide()
        $("#objectSelect").change(function() {
            let selectedVal = $("#objectSelect option:selected").val()
            if (selectedVal === "2") {
                $("#dialogUser").show()
                $(".dialog-s-center-h").height(180)
            } else {
                $("#dialogUser").hide()
                $(".dialog-s-center-h").height(130)
            }
        })
    },
    selectedValue:function(){
        let optionArr=["全部","已回复","未回复"];
        this.creatId("#cgstatus",optionArr);
    },
    creatId:function(id,optionArr){
        $(id).html();
        var str="";
        $.each(optionArr,function (i) {
            str+="<option value='"+i+"'>"+optionArr[i]+"</option>"
        });
        $(id).html(str);
        $(id).comboSelect();
    },
    getTableList() {
        $("#jid_loading").show()
        this.data.tableParams.platforType = $("#cgstatus option:selected").index() == 0 ? "" : $("#cgstatus option:selected").index()
        this.data.tableParams.platformName = $("#search_input_platfrom").val()
        jrequest.get("/api/commd-send/findAllChagang",this.data.tableParams).then(res => {
            this.data.datatable = res.data
            $("#jtable_chagang").bootstrapTable('destroy');
            this.creatTable(res)
            $("#jid_loading").hide()
            // $("#jtable_chagang").bootstrapTable('load',res.data);
        })
    },
    tableEvent:function(id,data,columns,paginationShow,total){
        let that = this
        $('#' + id).bootstrapTable({
            method: 'get',
            cache: false,
            height: 320,
            pagination: paginationShow,
            pageSize: that.data.tableParams.size,
            pageNumber:that.data.tableParams.page,
            showColumns: true,
            striped: true,
            columns: columns,
            sidePagination: 'server', // client or server
            totalRows: total,
            data :data,
            onPageChange: function (size, number) {
                console.log(number)
                that.data.tableParams.page = number
                that.data.tableParams.size = size
                that.getTableList()
            },
            formatNoMatches: function(){
                return '暂无数据';
            }
        });
    },
    creatTable:function(res){
        var self=this;
        var columnsOne = [
            {
                title : '序号',
                align: "center",
                formatter: function (value, row, index) {
                    //获取每页显示的数量
                    var pageSize=self.data.tableParams.size;
                    //获取当前是第几页
                    var pageNumber=self.data.tableParams.page;
                    //返回序号，注意index是从0开始的，所以要加上1
                    return pageSize * (pageNumber - 1) + index + 1;
                }
            },
            {
              field: "platformName",
              title: "运营商平台",
              visible: false
            },
            {
              field: "checkTheTime",
              title: "查岗时间",
              visible: true
            },
            {
              field: "sendContent",
              title: "查岗信息",
              visible: true
            },
            {
              field: "objectId",
              title: "对象类型",
              visible: true
            },
            {
              field: "objectType",
              title: "查岗对象",
              visible: true
            },
            {
              field: "platforType",
              title: "查岗状态",
              visible: true
            },
            {
              field: "platforName",
              title: "查岗应答人姓名",
              visible: false
            },
            {
              field: "platforPhone",
              title: "查岗应答人联系电话",
              visible: false
            },
            {
              field: "ackTime",
              title: "应答时间",
              visible: true
            },
            {
              field: "ackContent",
              title: "应答内容",
              visible: true
            }
        ];
        self.tableEvent("jtable_chagang",res.data,columnsOne,true,res.total);
    }
}

$(function(){
    jclass.initPage();
});



